package com.webtest.demo;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;


import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.webtest.core.BaseTest;
import com.webtest.dataprovider.NSDataProvider;
import com.webtest.dataprovider.TxtDataProvider;

public class FrontTest extends BaseTest {
	Alert alert;
	WebDriver driver;
	Actions action = new Actions(driver);
	
	@BeforeClass
	public void FrontLogin() {
		webtest.open("/");
		webtest.click("link=登录");
		webtest.type("name=username","huangxinyue");
		webtest.type("name=password", "123456");
		webtest.click("link=登录");
		webtest.click("link=huangxinyue");
		assertTrue(webtest.isDisplayed("link=退出登录"));
	}
	
	@AfterClass
	public void quit() {
		webtest.click("link=huangxinyue");
		webtest.click("link=退出登录");
	}
	
	
	
	@Test
	public void test1() throws Exception {
		//对头像删除改变的操作
		webtest.click("class=glyphicon glyphicon-trash text-danger");
		webtest.click("link=保存资料");
		Thread.sleep(1000);
	}
	

	
	@Test(dataProvider="user",dataProviderClass=TxtDataProvider.class)
	public void test2(String username,String phone,String email) throws Exception {
		//填写在线应聘  使用数据驱动txt
		webtest.click("link=加入我们");
		Thread.sleep(1000);
		webtest.click("在线应聘");
		Thread.sleep(1000);
		
		//index从0开始，0为默认值
		webtest.selectByVisibleText("name=para163", username);
		webtest.selectByVisibleText("name=para167", phone);
		webtest.selectByVisibleText("name=para168", email);
		Thread.sleep(1000);
		
		webtest.click("提交信息");
		Thread.sleep(1000);
		
	}
	
	@Test(dataProvider="b",dataProviderClass=TxtDataProvider.class)
	public void test3(String oldpassword,String password,String confirmpassword) throws Exception {
		//修改账号密码
		webtest.click("link=账号安全");
		webtest.click("link=修改");
		
		webtest.selectByVisibleText("name=oldpassword", oldpassword);
		webtest.selectByVisibleText("name=password", password);
		webtest.selectByVisibleText("name=confirmpassword", confirmpassword);
		Thread.sleep(1000);
		
		webtest.click("link=确定");
		
		
	}
	
	@Test(dataProvider="email",dataProviderClass=TxtDataProvider.class)
	public void test4(String email) throws Exception {
		//绑定邮箱
		webtest.click("link=账号安全");
		Thread.sleep(1000);
		
		webtest.click("xpath='//input[@class=\btn btn-primary btn-outline btn-squared btn-emailadd\"]'");
		Thread.sleep(1000);
		
		webtest.selectByVisibleText("name=email", email);
		Thread.sleep(1000);
		
		webtest.click("link=确定");
		
	}
	
	@Test(dataProvider="telephone",dataProviderClass=NSDataProvider.class)
	public void test5(String tel,String code,String phonecode) throws Exception{
		//绑定手机号
		webtest.click("link=账号安全");
		Thread.sleep(1000);
		
		webtest.click("xpath='//input[@class=\"btn btn-primary btn-outline btn-squared btn-teladd\"]'");
		Thread.sleep(1000);
		
		webtest.selectByVisibleText("name=tel", tel);
		webtest.selectByVisibleText("name=code", code);
		Thread.sleep(1000);
		
		webtest.click("link=获取验证码");
		Thread.sleep(1000);
		
		webtest.type("name=phonecode", phonecode);
		Thread.sleep(1000);
		
		webtest.click("link=确认");
		
	}
	
	@Test
	public void test6() throws Exception {
		//对个人信息的填充
		webtest.type("name=info_1", "某某有限公司");
		Thread.sleep(1000);
		
		webtest.type("name=info_2", "0317-2222");
		Thread.sleep(1000);
		
		webtest.type("name=info_3", "河北省石家庄市裕华区");
		Thread.sleep(1000);
		
		webtest.type("name=info_4", "890989");
		Thread.sleep(1000);
		
		webtest.type("name=info_5", "http://localhost//MetLnfo7.1.0");
		Thread.sleep(1000);
		
		webtest.click("link=保存资料");
		Thread.sleep(1000);
		
		alert.accept();
		Thread.sleep(1000);
		
	}
	
	@Test(dataProvider="search",dataProviderClass=TxtDataProvider.class)
	public void test7(String search) throws Exception{
		//对加入我们的搜索框的测试
		webtest.click("link=加入我们");
		Thread.sleep(1000);
		
		webtest.selectByVisibleText("id=0", search);
		Thread.sleep(1000);
		
		//回车
		action.sendKeys(Keys.ENTER).perform();
		Thread.sleep(1000);
	}
	
	@Test
	public void test8() throws Exception {
		//切换中英文
		webtest.click("link=英");
		Thread.sleep(1000);
		
		webtest.click("link=中");
		Thread.sleep(1000);
	}
	
	@Test
	public void test9() throws Exception {
		//网站首页切换轮播图
		webtest.click("link=网站首页");
		Thread.sleep(1000);

		webtest.mouseToElement("xpath='//div[@class=\"container\"]'");
		webtest.click("link=<");
		Thread.sleep(1000);
		
		webtest.click("link=>");
		Thread.sleep(1000);
	}

}
